<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目类型" prop="projectKindId">
        <el-select v-model="queryParams.projectKindId" placeholder="请选择项目类型" clearable>
          <el-option v-for="dict in dict.type.project_kind_id" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="daterangeCreatedDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="建设单位" prop="buildingDept" v-if="advanced">
        <el-input v-model="queryParams.buildingDept" placeholder="请输入建设单位" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="施工单位" prop="constructionDept" v-if="advanced">
        <el-input v-model="queryParams.constructionDept" placeholder="请输入施工单位" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="运输单位" prop="transportCompanyName" v-if="advanced">
        <el-input v-model="queryParams.transportCompanyName" placeholder="请输入运输单位" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="资源化单位" prop="disposalLandName" v-if="advanced" label-width="85px">
        <el-input v-model="queryParams.disposalLandName" placeholder="请输入运输单位" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工程地址" prop="address" v-if="advanced">
        <el-input v-model="queryParams.address" placeholder="请输入工程地址" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['report:resourceFilings:list']">导出
        </el-button>
        <advanced-search :advanced.sync="advanced" />
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="recordList">
      <el-table-column label="工程名称" align="center" prop="projectName" show-overflow-tooltip />
      <el-table-column label="项目类型" align="center" prop="projectKindId" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_kind_id" :value="scope.row.projectKindId" />
        </template>
      </el-table-column>
      <el-table-column label="工程地址" align="center" prop="address" show-overflow-tooltip />
      <el-table-column label="建设单位" align="center" prop="buildingDept" show-overflow-tooltip />
      <el-table-column label="施工单位" align="center" prop="constructionDept" show-overflow-tooltip />
      <el-table-column label="建筑垃圾运输单位" align="center" prop="transportCompanyName" show-overflow-tooltip />
      <el-table-column label="资源化利用单位" align="center" prop="disposalLandName" show-overflow-tooltip />
      <el-table-column label="结构类型" align="center" prop="structureType" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.structure_type_id" :value="scope.row.structureType" />
        </template>
      </el-table-column>
      <el-table-column label="建筑面积(m²)" align="center" prop="buildingArea" show-overflow-tooltip />
      <el-table-column label="预估建筑垃圾量(吨)" align="center" prop="rubbishPlanWeight" show-overflow-tooltip />
      <el-table-column label="项目实施时间(起止时间)" align="center" prop="buildingPeriod" show-overflow-tooltip />
      <el-table-column label="建设单位联系人" align="center" prop="buildingPerson" show-overflow-tooltip />
      <el-table-column label="建设单位联系方式" align="center" prop="buildingPhone" show-overflow-tooltip />
      <el-table-column label="备案日期" align="center" prop="approvalDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.approvalDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createdDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.current" :limit.sync="queryParams.size"
      @pagination="getList" />
  </div>
</template>

<script>
import { listResourceFilings } from "@/api/report/report";

export default {
  name: "Report",
  dicts: ['project_kind_id', 'structure_type_id'],
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 修改时间时间范围
      daterangeCreatedDate: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        projectName: null,
        projectKindId: null,
        createdDate: null,
        buildingDept: null,
        constructionDept: null,
        transportCompanyName: null,
        disposalLandName: null,
        address: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      advanced: false
    };
  },
  created () {
    this.getList();
  },
  methods: {
    /** 查询垃圾申报量统计列表 */
    getList () {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreatedDate && '' != this.daterangeCreatedDate) {
        this.queryParams.params["beginCreatedDate"] = this.daterangeCreatedDate[0];
        this.queryParams.params["endCreatedDate"] = this.daterangeCreatedDate[1];
      }
      listResourceFilings(this.queryParams).then(response => {
        this.recordList = response.records;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.daterangeCreatedDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download('report/resourceFilings/export', {
        ...this.queryParams
      }, `资源化备案登记统计表_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
